package com.dsy.xiangcun_index.controller;


import com.dsy.tools.entity.TbHistory;
import com.dsy.xiangcun_index.service.ITbTouService;
import com.dsy.xiangcun_index.service.ITbHistoryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestParam;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.dsy.tools.common.utils.QueryObj;
import javax.servlet.http.HttpSession;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author dsy
 * @since 2023-02-28
 */
@Controller
@RequestMapping("/history")
public class TbHistoryController {
    @Autowired
    ITbHistoryService historyService;
    @Autowired
    ITbTouService stuService;
    /**
     * 分页查看历史文化列表
     * @param m
     * @param page
     * @param limit
     * @param queryObj
     * @return
     */
    @RequestMapping("/getAllHistory")
    public String getAllHistory(Model m, @RequestParam(defaultValue = "1") long page, @RequestParam(defaultValue = "10") long limit, QueryObj queryObj, HttpSession session){

        QueryWrapper<QueryObj> wrapper = new QueryWrapper<>();

        wrapper.setEntity(queryObj);

        IPage<TbHistory> historyPage = historyService.getAllHistory(page,limit,wrapper);
        m.addAttribute("historyPage",historyPage);
        m.addAttribute("page",page);
        m.addAttribute("queryObj",queryObj);
        return "/history/history-list";
    }
    /**
     * 根据历史文化Id查询
     * @param m
     * @param historyId
     * @return
     */
    @RequestMapping("/getHistoryById")
    public String getHistoryById(Model m,Integer historyId){
        TbHistory history= historyService.getHistoryById(historyId);
        m.addAttribute("history",history);
        return "/history/history-look";
    }


}
